Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add length option for shorten_path #886

Merged
merged 5 commits into from
Jul 16, 2021

Conversation

l-kershaw
Copy link
Contributor

@l-kershaw l-kershaw commented Jun 2, 2021

WIP

Adding option to provide a length for shorten_path, not just a boolean, as suggested in #880.
Implemented using Path:shorten from plenary as the function in telescope had gotten out of date in comparison.

Todo:

  • Update documentation

Feedback welcome 🙂

@Conni2461
Copy link
Member

2 Things:

  • It was always the idea to move from telescope.path to plenary.path and @anott03 has done a lot of work in plenary.path and here move from telescope/path to plenary/path #473 I do not know why this PR was never finished, it was around that time when i took a break. So you would need to speak with him how everything should continue
  • There is also this PR Consistent filepath display and code cleanup. #839 which simplifies the whole display path thing and would make this PR way simpler. So i wanna at least wait till this is done.

Otherwise yes cool idea thanks :)

@anott03
Copy link
Contributor

anott03 commented Jun 2, 2021

@Conni2461 I don't really know what happened with #473 either - I ended up taking a bit of a break as well. If I'm not mistaken, it was before TJ refactored actions so there's likely some work to be done before we can merge it.

@l-kershaw
Copy link
Contributor Author

Ah, okay. I'll have a look at #473 and #839 🙂

@caojoshua
Copy link
Contributor

fyi #839 is merged. This PR is unblocked. This would be a nice change :)

@l-kershaw
Copy link
Contributor Author

I think we're also still waiting on #473 before this PR can proceed.
Although that PR hasn't been active in nearly a month, so not sure what is best to do at this point.

@Conni2461
Copy link
Member

Yeah i haven't received an answer. Hmm i am thinking of just finishing it. I think anott03 is a little bit frustrated with me. I haven't done the best job of helping with that PR.

If i have a evening of free time next week, i will spend it on 473. I dont wanna block stuff that is actually super cool :)

@anott03
Copy link
Contributor

anott03 commented Jul 14, 2021

@l-kershaw apologies for blocking you so long with #473! It's merged now so this should be good to go (I think Conni had some minor fixes he wanted to make – just double check that those are done). Let me know if you ever want help or feedback with this!

@l-kershaw l-kershaw force-pushed the feat/path_shorten_len branch from be738ba to c2c32ee Compare July 14, 2021 19:38
@l-kershaw
Copy link
Contributor Author

@anott03 no worries at all! Developer time is a scarce resource in open source projects, and I appreciate all of the time you spent on #473 🙂


I've reimplemented the shorten_len option, but I'm not sure I'm happy with the way the user configures it.
Since #839 has implemented path_display as a sort of "flag list", we can't pass a length in with the option.
So the shorten_len is separate from the rest of the path_display stuff, which feels weird.

Does anyone have any thoughts on better ways to implement this option?

@anott03
Copy link
Contributor

anott03 commented Jul 14, 2021

Does anyone have any thoughts on better ways to implement this option?

I'll back at my desk later tonight and I'll see if I can come up with any ideas then :)

lua/telescope/path.lua Outdated Show resolved Hide resolved
@Conni2461
Copy link
Member

Conni2461 commented Jul 14, 2021

For interface i have 2 thoughts. path_display = { "shorten", 2 } for example (so index after shorten is potential len) or path_display = { "shorten" } (still valid) + support for path_display = { shorten = { len = 2 } }.

Also I would prefer len to be always a number, so we dont need tonumber. The util shorthand can then only be Path:new(filename):shorten(len) because plenary accepts either nil or a number >= 1 and already does the assert https://github.com/nvim-lua/plenary.nvim/blob/8bae2c1fadc9ed5bfcfb5ecbd0c0c4d7d40cb974/lua/plenary/path.lua#L346-L352

@Conni2461
Copy link
Member

Thoughts on both interface ideas? You can also always ask tj if you are stuck, he will then make the decision 😆

@l-kershaw
Copy link
Contributor Author

@Conni2461 I don't really like either of your suggested configuration methods, they both feel weird to me (not that my method is any better, mind you). There seem to be two contradictory goals with configuring this:

  1. keeping all the configuration for how the path is displayed in the path_display object.
  2. keeping the path_display object as some sort of "flag list" of strings.

I'm not sure what to do, since these goals don't seem compatible and I don't really know which one to sacrifice in favour of the other. @tjdevries do you have any thoughts on this?


Regarding the change to utils.path_shorten I agree that we should remove all of this logic from telescope as it is handled on the plenary side. However, since this basically amounts to utils.path_shorten being a straight wrapper (with no additional stuff) for Path:shorten, is it actually worth keeping utils.path_shorten in telescope at all?

@anott03
Copy link
Contributor

anott03 commented Jul 14, 2021

A quick project wide search for path_shorten only yielded one result – it's definition – so I see no reason to keep the function there (and even if there were uses, I'd say we should switch those to plenary and remove it from utils).

@Conni2461
Copy link
Member

We will keep the shorthand for now because we dont wanna break extensions, we can deprecate it later :)

In hindsight this path_display = { shorten = { len = 2 } } is stupid. We can also do this path_display = { shorten = 2 }.
I know that path_display is a list of strings but i kinda like to keep all the display path related stuff under one key and i am not saying remove the other version (list of strings)

Also we had a discussion here #961 where i said path_display could either be a table or a function(opts, path) so more advanced people have 100% control of the displaying

l-kershaw and others added 4 commits July 16, 2021 16:58
- adds option to configure the length of shortened parts of filenames
- only affects paths when "shorten" is in `path_display`
- reimplemented based on changes in nvim-telescope#473 and nvim-telescope#839
- also deprecates `utils.path_shorten` and passes straight to `plenary`s `Path:shorten`

[docgen] Update doc/telescope.txt
skip-checks: true
@l-kershaw l-kershaw force-pushed the feat/path_shorten_len branch from bfc9475 to f8f267e Compare July 16, 2021 16:03
@l-kershaw
Copy link
Contributor Author

@Conni2461 I think that your path_display = { shorten = 2 } style is the best option so far.
I've implemented it and updated the docs accordingly. I also added a deprecation warning for utils.path_shorten.

I don't think there's a better way to deal with this option, so I'm happy to just keep it like this.


@Conni2461 @anott03 is there anything else you think I should change?

@l-kershaw l-kershaw merged commit 1866265 into nvim-telescope:master Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants